package faceb.server.util;

import java.io.File;
import java.nio.file.Paths;

import org.apache.commons.io.FileUtils;

public class InitJsp {
	public static void initJsp(String htmlPath,String jspPath,String headPath) throws Exception{
		File htmlroot= new File(htmlPath);
		File jspHead = new File(headPath);
		String head = FileUtils.readFileToString(jspHead,"utf-8");
		File files[] =htmlroot.listFiles();
		for(File file :files ){
			String filename = file.getName();
			String prefix = filename.substring(0, filename.lastIndexOf("."));
			String htmlString = FileUtils.readFileToString(file, "utf-8");
			String all = head +"\r\n"+htmlString;
			File jspFile = Paths.get(jspPath, prefix+".jsp").toFile();
			FileUtils.writeStringToFile(jspFile, all, "utf-8");
		}
		
	}
	
	public static void main(String[] args) {
		try {
			initJsp("D:\\initjsp\\html", "D:\\initjsp\\jsp", "D:\\initjsp\\head\\head.txt");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
